﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QLNS.aspFrm
{
    public partial class frmDanhSachCanBoMienNhiem : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();

            System.Data.DataTable dtTK = MakeTable();

            foreach (var item in context.GetDSCBCCVCMienNhiem(int.Parse(Request.QueryString["nam"])))
            {
                System.Data.DataRow row;
                row = dtTK.NewRow();
                row["HoTen"] = item.HoTen;
                //Ngay sinh
                if (item.NgaySinh == null)
                {
                    row["NgaySinhNam"] = "";
                    row["NgaySinhNu"] = "";
                }
                else
                    if (item.GioiTinh != null && item.GioiTinh.Equals("Nam"))
                    {
                        row["NgaySinhNam"] = item.NgaySinh.Value.ToShortDateString();
                    }
                    else if (item.GioiTinh != null && item.GioiTinh.Equals("Nữ")) row["NgaySinhNu"] = item.NgaySinh.Value.ToShortDateString();
                
                row["GioiTinh"] = item.GioiTinh;
                row["QueQuan"] = item.QueQuan;
                row["ChucVu"] = item.ChucVu;
                //Tu Ngay
                if (item.TuNgay == null)
                    row["TuNgay"] = "";
                else row["TuNgay"] = item.TuNgay.Value.ToShortDateString();  
              
                row["ChuyenMon"] = item.ChuyenMon;
                row["QLNhaNuoc"] = item.QLNhaNuoc;
                row["LyLuan"] = item.LyLuan;
                row["TinHoc"] = item.TinHoc;
                row["NgoaiNgu"] = item.NgoaiNgu;
                // Ngay huong luong
                if (item.NgayTuyenDung == null)
                    row["NgayTuyenDung"] = "";
                else row["NgayTuyenDung"] = item.NgayTuyenDung.Value.ToShortDateString();
                dtTK.Rows.Add(row);
               
                // Thoi diem thong bao nghi huu
                if (item.NgayVaoDang == null)
                    row["NgayVaoDang"] = "";
                else
                    row["NgayVaoDang"] = item.NgayVaoDang.Value.ToShortDateString();

                // Thoi diem nghi huu
                if (item.NgayVaoChinhThuc == null)
                    row["NgayVaoChinhThuc"] = "";
                else
                    row["NgayVaoChinhThuc"] = item.NgayVaoChinhThuc.Value.ToShortDateString(); 
               
                // Nam Bao Cao
                row["NamBaoCao"] =Request.QueryString["nam"];
            }

            CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            string strRptPath = Server.MapPath("~/") + "Reports//Report_DanhSachCanBoMienNhiem.rpt";
            //Loading Report
            rd.Load(strRptPath);

            // Setting report data source
            if (dtTK != null && dtTK.GetType().ToString() != "System.String")
                rd.SetDataSource(dtTK);


            CrystalReportViewer1.ReportSource = rd;
        }

        private System.Data.DataTable MakeTable()
        {
            System.Data.DataTable table = new System.Data.DataTable("Table");
            System.Data.DataColumn column;

            // Create new DataColumn, set DataType, 

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "HoTen";
            column.Caption = "HoTen";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgaySinh";
            column.Caption = "NgaySinh";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "GioiTinh";
            column.Caption = "GioiTinh";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "QueQuan";
            column.Caption = "QueQuan";
            // Add the column to the table.
            table.Columns.Add(column);


            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ChucVu";
            column.Caption = "ChucVu";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TuNgay";
            column.Caption = "TuNgay";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ChuyenMon";
            column.Caption = "ChuyenMon";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "QLNhaNuoc";
            column.Caption = "QLNhaNuoc";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "LyLuan";
            column.Caption = "LyLuan";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TinHoc";
            column.Caption = "TinHoc";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgoaiNgu";
            column.Caption = "NgoaiNgu";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgayTuyenDung";
            column.Caption = "NgayTuyenDung";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgayVaoDang";
            column.Caption = "NgayVaoDang";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgayVaoChinhThuc";
            column.Caption = "NgayVaoChinhThuc";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NamBaoCao";
            column.Caption = "NamBaoCao";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgaySinhNam";
            column.Caption = "NgaySinhNam";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgaySinhNu";
            column.Caption = "NgaySinhNu";
            // Add the column to the table.
            table.Columns.Add(column);

            return table;
        }

        
    }
}